#ifndef POOL_H__
#define POOL_H__

#include <pthread.h>
#include "queue.h"

#define MAXJOB 10 //为了测试阻塞改小的
#define MIN_FREETHR_NR 3
#define MAX_FREETHR_NR 5

//任务结构
typedef struct{
	void *(*job)(void *s);
	void *arg;
}task_t;

typedef struct{
	//管理者线程
	pthread_t admin_ttid;
	//工作线程结构数组的启示地址
	pthread_t *workers;
	//任务队列
	queue_t *task_queue;
	//线程池结构
	int max_threads;
	int min_free_threads;
	int max_free_threads;
	int live_threads;
	int busy_threads;
	int exit_threads; //后曾，管理者线程当需要线程终止的时候，累加
	int shutdown; // 1 池关闭  0 池正常

	pthread_mutex_t mut_pool;
	pthread_mutex_t mut_busy;
	pthread_cond_t queue_not_empty;
	pthread_cond_t queue_not_full;
}pool_t;

extern int pool_init(pool_t **mypool, int capacity);

extern int pool_add_task(pool_t *mypool, const task_t *t);

extern void pool_destroy(pool_t *mypool);

#endif